package com.whut.googleplay.utils;

import com.whut.googleplay.fragment.AppFragment;
import com.whut.googleplay.fragment.BaseFragment;
import com.whut.googleplay.fragment.CategoryFragment;
import com.whut.googleplay.fragment.GameFragment;
import com.whut.googleplay.fragment.HomeFragment;
import com.whut.googleplay.fragment.HotFragment;
import com.whut.googleplay.fragment.RecommentFragment;
import com.whut.googleplay.fragment.SubjectFragment;
import com.whut.googleplay.global.Constants;

import java.util.HashMap;

/**
 * ============================================================
 * 作 者 :        xyb
 * 版 本 :        1.0
 * 创建日期 ：     2016-04-25 下午2:45
 * 描 述 ：
 * 修订历史 ：
 * ============================================================
 **/
public class FragmentFactory {


    private static HashMap<Integer, BaseFragment> mFragmentMap = new HashMap<>();
    private static BaseFragment mBaseFragment;

    public static BaseFragment createFragment(int position) {

        mBaseFragment = mFragmentMap.get(position);

        if (mBaseFragment == null) {
            switch (position) {

                case Constants.TAB_HOME:
                    mBaseFragment = new HomeFragment();
                    break;
                case Constants.TAB_APP:
                    mBaseFragment = new AppFragment();
                    break;
                case Constants.TAB_GAME:
                    mBaseFragment = new GameFragment();
                    break;
                case Constants.TAB_SUBJECT:
                    mBaseFragment = new SubjectFragment();
                    break;
                case Constants.TAB_RECOMMENT:
                    mBaseFragment = new RecommentFragment();
                    break;
                case Constants.TAB_CATEGORY:
                    mBaseFragment = new CategoryFragment();
                    break;
                case Constants.TAB_HOT:
                    mBaseFragment = new HotFragment();
                    break;
            }
            mFragmentMap.put(position, mBaseFragment);
        }
        return mBaseFragment;
    }

}
